import Vue from 'vue'
import VueRouter from 'vue-router'
import Index from '../views/index.vue'
import Login from '../views/login.vue'
import Pro from '../views/proChose.vue'
import History from '../components/history'


Vue.use(VueRouter)

const routes = [
  
  {
    path: '/',
    component: Index,
    
  },
  {
    path:'/history',
    // component:History
    component:()=>import('../components/history')
  },
  {
    path:'/login',
    // component:Login
    component:()=>import('../views/login.vue')
    
  },
  {
    path:'/projects',
    // component:Pro
    component:()=>import('../views/proChose.vue')

  },



]

const router = new VueRouter({
  routes
})
// 切换路由之前 导航守卫  路由拦截
router.beforeEach((to, from, next) => {
  var  userId = sessionStorage.getItem('userId')
   if(to.path == '/login'){
    next()
   }else{
    if(userId){
      next()
    }else{
      next('/login')
    }
   }
  })
  

export default router
